{include file="header.html"}
<div id="main">
	{include file="menus.html"}
	<div id="rightCon" class="clearfix layui-body">
		<div class="scroller">
			<div class="search-form clearfix">
				<form method="get" id="formSearch">
					<div class="webkit-box box-align-center">
						<input type="hidden" name="r" value="deposit/drawlist" />
						<select class="querySelect" name="field">
							{html_options options=$search_options selected=$smarty.get.field}
						</select>
						<input class="infoTableInput mr10" type="text" name="search_name"
							value="{$smarty.get.search_name}" />
						<label>{$lang.trade_status}</label>
						<select class="querySelect" name="status">
							<option value="">{$lang.no_limit}</option>
							{html_options options=$status_list selected=$smarty.get.status}
						</select>
						{$lang.amount_from}
						<input class="queryInput2" type="text" value="{$smarty.get.amount_from}" name="amount_from" />
						{$lang.to}
						<input class="queryInput2" type="text" value="{$smarty.get.amount_to}" name="amount_to"
							class="pick_date" />
					</div>
					<div class="webkit-box box-align-center mt20">
						{$lang.add_time_from}
						<input class="queryInput" type="text" value="{$smarty.get.add_time_from}" id="add_time_from"
							name="add_time_from" class="pick_date" />
						{$lang.to}
						<input class="queryInput" type="text" value="{$smarty.get.add_time_to}" id="add_time_to"
							name="add_time_to" class="pick_date" />

						<input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7"
							value="{$lang.query}" />
						<!--{if $filtered}-->
						<a class="layui-btn layui-btn-primary layui-btn-sm box-align-center"
							href="{url route='deposit/drawlist'}">{$lang.cancel_query}</a>
						<!--{/if}-->
					</div>
				</form>
			</div>
			<div class="tablegrid">
				<table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
			</div>
			{include file="version.html"}
		</div>
	</div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-bg-blue" lay-event="refuse"><i class="layui-icon layui-icon-edit"></i>提现拒绝</button>
		<button class="layui-btn layui-btn-primary layui-border-black" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出数据</button>
	</div>
</script>

<script type="text/html" id="colBar">
	<a class="ml5 mr5 blue pointer" lay-event="manual">人工转账</a>
	<a class="ml5 mr5 blue pointer" lay-event="online">在线转账</a>
</script>

<script>
	layui.use('table', function () {
		var table = layui.table;

		table.render({
			elem: '#tablegrid'
			//,skin: 'line'
			, url: url(['deposit/drawlist', $("#formSearch").serializeJson()])
			, toolbar: '#toolbar'
			, defaultToolbar: ['filter', /*'exports',*/ 'print']
			, title: '提现记录'
			//, size: 'lg'
			, cols: [[
				{ type: 'checkbox', fixed: 'left' }
				, { field: 'draw_id', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
				, { field: 'tradeNo', title: '交易号', width: 200, sort: true, }
				, { field: 'orderId', title: '商户订单号', width: 130, sort: true }
				, { field: 'amount', title: '提现金额（元）', width: 150, sort: true }
				, { field: 'username', title: '提现账号', width: 110, sort: true }
				, {
					field: 'drawtype', title: '提现到', width: 100, sort: true, templet: function (res) {
						return res.drawtype == 'alipay' ? '支付宝' : (res.drawtype == 'wxpay' ? '微信' : '银行卡');
					}
				}
				, {
					field: 'account', title: '账户', width: 180, sort: true, templet: function (res) {
						return res.drawtype == 'bank' ? res.bank + '(' + res.account + ')' : res.account;
					}
				}
				, { field: 'name', title: '真实姓名', width: 100, align: 'center' }
				, {
					field: 'status', title: '状态', width: 160, sort: true, templet: function (res) {
						return lang[res.status.toLowerCase()];
					}
				}
				, { field: 'add_time', title: '创建时间', width: 180, sort: true, align: 'center' }
				, { field: 'end_time', title: '完成时间', width: 180, sort: true, align: 'center' }
				, { fixed: 'right', title: '操作', toolbar: '#colBar', width: 180, align: 'center' }
			]]
			, page: {
				theme: 'blue'
			},
			done: function (res, curr, count) {
				$.each(res.data, function (i, item) {
					if (item.status != 'WAIT_ADMIN_VERIFY') {
						$('.layui-table-fixed-r .layui-table').find('tr[data-index=' + i + ']').find('a').removeClass('pointer').attr('lay-event', '').css('color', '#999');
					}
				})
			}
		});

		//监听头工具栏事件
		table.on('toolbar(tablegrid)', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			if (checkStatus.data.length <= 0) {
				return false;
			}
			var items = new Array();
			$.each(checkStatus.data, function (i, item) {
				items.push(item.draw_id);
			});
			if (obj.event === 'refuse') {
				if (items.length > 1) {
					layer.msg('每次仅能处理一条提现记录！');
					return false;
				}
				drawrefuse(checkStatus.data[0], table);
			}
			else if (obj.event === 'export') {
				window.location.href = url(['deposit/export', $.extend($("#formSearch").serializeJson(), { id: items.join(','), model: 'draw' })]);
			}
		});

		//监听行工具事件
		table.on('tool(tablegrid)', function (obj) {
			var data = obj.data;

			var message = '';
			if (obj.event === 'manual') {
				var accountInfo = data.drawtype == 'alipay' ? '支付宝('+data.account+')' : (data.drawtype == 'wxpay' ? '微信号('+data.account+')' : data.bank+'('+data.account+')');
				message = '务必认真核对提现信息，点击“确定”前，请确保款项已<p>手动转账至账户：' + accountInfo + '</p>';
				transfer(data, table, obj.event, message);
			}
			if (obj.event === 'online') {
				if (data.drawtype != 'alipay') {
					return layer.open({ content: lang.drawtype_disallow, title: lang.notice });
				}
				message = '务必认真核对提现信息，点击“确定”后，款项将从平台支付宝<p>自动划款至提现支付宝账户：' + data.account + '，请谨慎操作！</p>';
				transfer(data, table, obj.event, message);
			}
			
		});
	});

	$(function () {
		$('#add_time_from').datepicker({ dateFormat: 'yy-mm-dd' });
		$('#add_time_to').datepicker({ dateFormat: 'yy-mm-dd' });
	});
	function transfer(obj, table, method, message) {
		layer.confirm(message, { btn: [lang.confirm, lang.close], title: lang.notice }, function (index) {
			$.ajaxSettings.async = false;
			$.getJSON(url(['deposit/drawverify']), { id: obj.draw_id, method: method }, function (data) {
				if (data.done) {
					layer.close(index);
					layer.msg(data.msg);
					table.reload('tablegrid');
				} else {
					layer.close(index);
					layer.msg(data.msg);
					//table.reload('tablegrid');
				}
			});
		});
	}
	function drawrefuse(obj, table) {
		layer.prompt({
			formType: 2,
			value: '提现账户信息填写不完整',
			title: '拒绝原因',
		}, function (value, index, elem) {
			$.ajaxSettings.async = false;
			$.getJSON(url(['deposit/drawrefuse']), { id: obj.draw_id, remark: value }, function (data) {
				if (data.done) {
					layer.close(index);
					layer.msg(data.msg);
					table.reload('tablegrid');
				} else {
					layer.close(index);
					layer.msg(data.msg);
					//table.reload('tablegrid');
				}
			});
		});
	}
</script>
{include file="footer.html"}